package com.sld.cloud.controller;

import com.sld.cloud.pojo.Payment;
import com.sld.cloud.service.IMessageProvider;
import com.sld.cloud.vojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/consumer")
public class OrderController {

    private String PRIMARY_URL = "http://CLOUD-GATEWAY/";

    @Resource
    private RestTemplate restTemplate;

    // 消息发送接口
    @Resource
    private IMessageProvider messageProvider;

    @GetMapping("/payment")
    public Result save( Payment payment){
        return restTemplate.postForObject(PRIMARY_URL+"payment",payment,Result.class);
    }

    @GetMapping("/payment/{id}")
    public Result getPaymentById(@PathVariable("id") Long id){
        return restTemplate.getForObject(PRIMARY_URL+"payment/"+id,Result.class,id);
    }
    @GetMapping(value = "/sendMessage")
    public String sendMessage()
    {
        return messageProvider.send();
    }


}
